package com.cnswhy.cloud.server.comsumer.consumer.customer;

import com.cnswhy.cloud.server.common.entity.enumeration.SubWalletType;
import com.cnswhy.cloud.server.common.entity.enumeration.WalletType;
import com.cnswhy.cloud.server.common.entity.mq.RegisterMsg;
import com.cnswhy.cloud.server.comsumer.event.RegisterMessageEvent;
import com.cnswhy.cloud.server.core.entity.CustomerWallet;
import com.cnswhy.cloud.server.core.service.CustomerWalletService;
import com.cnswhy.cloud.server.core.wallet.WalletService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CreateWalletConsumer implements RegisterMessageEvent {
    @Autowired
    CustomerWalletService customerWalletService;
    @Autowired
    WalletService walletService;
    @Override
    public void register(RegisterMsg registerMsg) {
        log.info("给用户新增默认钱包:{} {}",registerMsg.getCustomerId(),registerMsg.getLoginName());
        for(WalletType walletType : WalletType.values()){
            walletService.checkAndCreate(registerMsg.getCustomerId(),walletType,0L);
        }
        /*CustomerWallet customerWallet = new CustomerWallet();
        customerWallet.setCustomerId(registerMsg.getId());
        customerWallet.setWalletType(WalletType.BALANCE);
        customerWallet.setAvlbBalance(0L); //可用：分
        customerWallet.setFronzenBalance(0L); //冻结：分
        customerWalletService.save(customerWallet);*/
        log.info("给用户添加钱包完成");

    }
}
